
let token = ''; // 凭证
// process.env.NODE_ENV === 'development' ? '192.168.0.1' : 'https://fullhouse.qinyuan.cn/api'; //环境配置
let baseUrl = process.env.NODE_ENV === 'development' ? 'https://fh4.qinyuan.cn/api' : 'https://fh4.qinyuan.cn/api';

function service(options = {}) {
  options.url = `${baseUrl}${options.url}`;
  //配置请求头
  options.header = {
    'content-type': 'application/json',
    // 'accessToken': `${token}` //Bearer 
  };

  return new Promise((resolved, rejected) => {
    //成功
    options.success = (res) => {
      const code = Number(res.data.code)
      if (code == 200 || code == 1) {  //请求成功
        resolved(res.data);
      } else {
        uni.showToast({
          icon: 'none',
          duration: 3000,
          title: `${res.data.msg}`
        });
        rejected(res.data.msg);//错误
      }
    }
    //错误
    options.fail = (err) => {
      rejected(err); //错误
    }
    uni.request(options);
  });
}

export default service;